<?php

namespace App\Http\Controllers\Admin;

use App\Menu;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class IndexController extends Controller
{
    //首页
    public function index(){

        return view('admin.layout');
    }
    //main
    public function main(){
        return view('admin.main');
    }
    //退出登陆
    public function logout(){
        Auth::logout();

        return redirect('/admin/login');
    }
    //报错信息
    public function error(){
        return view('admin.error.permission');
    }
    //得到授权菜单
    public function menu(){

        $user=User::find(Auth::id());
        $allPermission=$user->getAllPermissions()->pluck('name')->toArray();
       return  $menu=Menu::with(['children'=>function($query) use ($allPermission){
           $query->whereIn('permission',$allPermission)
                 ->orderBy('order','desc');
        }])->where('parent_id',0)->orderBy('order','desc')->get();

    }
}
